﻿@{
    ViewBag.Title = "颜色列表";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}
<script language="javascript" type="text/javascript">
    function doSearch() {
        $('#dg').datagrid('load', {
        }); 
    }
 
    function addColorInfo() {
        $('#dlg').dialog('open').dialog('setTitle', '新增');
        $('#fm').form('clear');
        url = '/ColorInfo/AddColorInfo';
    }
    function editColorInfo() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show("请选择数据在编辑!");
            return;
        }
        $('#fm').form('clear');
        $('#dlg').dialog('open').dialog('setTitle', '编辑'); //
        $('#fm').form('load', row);
        url = '/ColorInfo/EditColorInfo';
    }

    function delColorInfo() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show("请选择数据在编辑!");
            return;
        }
        $.post("/ColorInfo/DelColorInfo", { ColorId: row.ColorId }, function (json) {
            Helper.Show(json.Msg);
            if (json.Code == 1) {
                doSearch();
            }
        });
    }

    function saveColor() {
        $.messager.progress({
            title: '请稍后',
            msg: '数据保存中...',
        });
        window.setTimeout(function () {
            $('#fm').form('submit', {
                url: url,
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (json) {
                    $.messager.progress('close');
                    var json = eval('(' + json + ')');
                    Helper.Show(json.Msg);
                    if (json.Code == 1) {
                        $('#fm').form('clear');
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('reload');
                    }
                }
            });
        }, 2000);
    }
</script>
<table id="dg" class="easyui-datagrid" style="width:100%; height: 600px;"
       url="/ColorInfo/GetColorInfoList" toolbar="#tb" title="颜色列表" rownumbers="true" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="ColorName">
                颜色
            </th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 5px; height: auto;">
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addColorInfo()">添加</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editColorInfo()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-cut" plain="true" onclick="delColorInfo()">删除</a>
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search"
           onclick="doSearch()">查询</a>
    </div>
</div>


<div id="dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-save',buttons:'#dlg-buttons'" closed="true" style="width: 380px; height: 150px;" modal="true">
    <form id="fm" method="post" novalidate>
        <input name="ColorId" type="hidden" />
        <div class="fitem1">
            <label>
                颜色:
            </label>
            <input name="ColorName" class="easyui-textbox " data-options="required:true,validType:'length[1,20]'" autocomplete="off" style="width: 173px; height: 30px;" />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveColor()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
